package Batch::Cluster::Result;

use Moose;
use List::Util qw{ first };


has 'results' =>
(
	traits => ['Array'],
	is => 'rw',
	isa => 'ArrayRef[Any]',
	required => 1,
	default => sub { [] },
	handles =>
	{
    	all_results => 'elements',	
    	add_result  => 'push',
    	num_result  => 'count',
    	get_result  => 'shift',
	}
);


use overload bool  => \&to_bool,
             fallback => 1;

sub to_bool 
{
	my $self = shift;
	my $element = first { !$_->result() } $self->all_results();
	return 1 unless defined $element;
	return 0;
}


sub add_result_in_order
{
	my $self = shift;
	my ($machine, $order) = @_;
	
	die "Se esperaba un objeto de la clase GRID::Machine::Result" unless ref $machine eq 'GRID::Machine::Result';
	die "Se esperaba un índice en donde insertar la máquina" unless $order =~ m/\d+/;
	
	$self->results->[$order] = $machine;	
}

__PACKAGE__->meta->make_immutable;

no Moose;

1;

__END__

=head1 NAME

Batch::Cluster::Result - Clase que maneja los resultados obtenidos con Batch::Cluster

=head1 SYNOPSIS
		
=head1 DESCRIPTION

Define un resultado obtenido por una llamada a algún método Batch::Cluster. Además, gestiona
los resultados de las operaciones realizadas sobre las máquinas remotas, de forma conjunta y 
sencilla.

=head1 AUTHOR

Nicolás Pernas Maradei, E<lt>nicopernas@gmail.comE<gt>
Francisco José Cabrera Hernández, E<lt>alu3651@etsii.ull.esE<gt>
Romén Rodríguez Gil, E<lt>alu3718@etsii.ull.esE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2011 by Nicolás Pernas Maradei, Francisco José Cabrera Hernández, Romén Rodríguez Gil

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.9 or,
at your option, any later version of Perl 5 you may have available.


=cut
